package com.seteam.collabcrossword;

import com.seteam.collabcrossword.exceptions.CoordinatesException;

/**
 * This class provides static methods to create different kinds of {@link Tile}s
 */
public class TileFactory {
    /**
     * Creates a tile that is shared between two words
     *
     * @param coordinates the coordinates of the tile on the board
     * @return an instance of {@link Tile}
     * @throws CoordinatesException if the coordinates passed is null
     */
    public static Tile createSharedTile(final Coordinates coordinates) throws CoordinatesException {
        CollabCrosswordUtils.checkNotNull(coordinates, Globals.COORDINATES_ERROR + "The coordinates passed to " +
                "createSharedTile cannot be null");
        Tile tile = new Tile(coordinates);
        tile.setShared(true);
        return tile;
    }

    /**
     * Creates a tile that is blocked. This tile will not be editable
     *
     * @param coordinates the coordinates of the tile on the board
     * @return an instance of {@link Tile}
     * @throws CoordinatesException if the coordinates passed is null
     */
    public static Tile createBlockedTile(final Coordinates coordinates) throws CoordinatesException {
        CollabCrosswordUtils.checkNotNull(coordinates, Globals.COORDINATES_ERROR + "The coordinates passed to " +
                "createBlockedTile cannot be null");
        Tile tile = new Tile(coordinates);
        tile.setBlocked(true);
        return tile;
    }

    /**
     * Creates a tile that is neither blocked nor shared
     *
     * @param coordinates the coordinates of the tile on the board
     * @return an instance of {@link Tile}
     * @throws CoordinatesException if the coordinates passed is null
     */
    public static Tile createDefaultTile(final Coordinates coordinates) throws CoordinatesException {
        CollabCrosswordUtils.checkNotNull(coordinates, Globals.COORDINATES_ERROR + "The coordinates passed to " +
                "createDefaultTile cannot be null");
        Tile tile = new Tile(coordinates);
        return tile;
    }

    /**
     * Creates an empty tile
     *
     * @return an instance of {@link Tile} with all fields set to default values
     */
    public static Tile createEmptyTile() {
        return new Tile();
    }
}
